package cn.lingyangwl.agile.pay.pay.model.rqrs.payorder;

import cn.lingyangwl.agile.pay.common.constants.Cs;
import cn.lingyangwl.agile.pay.model.rqrs.pay.payorder.UnifiedOrderRQ;
import cn.lingyangwl.agile.pay.pay.model.rqrs.payorder.payway.*;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

/**
 * 创建订单请求参数对象
 * 聚合支付接口（统一下单）
 *
 * @author shenguangyang
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class UnifiedOrderExtRQ extends UnifiedOrderRQ {

    /**
     * 返回真实的bizRQ
     */
    public UnifiedOrderExtRQ buildBizRQ() {
        if (Cs.PAY_WAY_CODE.ALI_BAR.equals(wayCode)) {
            AliBarOrderExtRQ bizRQ = JSONObject.parseObject(StringUtils.defaultIfEmpty(this.channelExtra, "{}"), AliBarOrderExtRQ.class);
            BeanUtils.copyProperties(this, bizRQ);
            return bizRQ;
        } else if (Cs.PAY_WAY_CODE.ALI_JSAPI.equals(wayCode)) {
            AliJsapiOrderExtRQ bizRQ = JSONObject.parseObject(StringUtils.defaultIfEmpty(this.channelExtra, "{}"), AliJsapiOrderExtRQ.class);
            BeanUtils.copyProperties(this, bizRQ);
            return bizRQ;
        } else if (Cs.PAY_WAY_CODE.ALI_LITE.equals(wayCode)) {
            AliLiteOrderExtRQ bizRQ = JSONObject.parseObject(StringUtils.defaultIfEmpty(this.channelExtra, "{}"), AliLiteOrderExtRQ.class);
            BeanUtils.copyProperties(this, bizRQ);
            return bizRQ;
        } else if (Cs.PAY_WAY_CODE.QR_CASHIER.equals(wayCode)) {
            QrCashierOrderRQ bizRQ = JSONObject.parseObject(StringUtils.defaultIfEmpty(this.channelExtra, "{}"), QrCashierOrderRQ.class);
            BeanUtils.copyProperties(this, bizRQ);
            return bizRQ;
        } else if (Cs.PAY_WAY_CODE.WX_JSAPI.equals(wayCode)) {
            WxJsapiOrderExtRQ bizRQ = JSONObject.parseObject(StringUtils.defaultIfEmpty(this.channelExtra, "{}"), WxJsapiOrderExtRQ.class);
            BeanUtils.copyProperties(this, bizRQ);
            return bizRQ;
        } else if (Cs.PAY_WAY_CODE.WX_LITE.equals(wayCode)) {
            WxLiteOrderExtRQ bizRQ = JSONObject.parseObject(StringUtils.defaultIfEmpty(this.channelExtra, "{}"), WxLiteOrderExtRQ.class);
            BeanUtils.copyProperties(this, bizRQ);
            return bizRQ;
        } else if (Cs.PAY_WAY_CODE.WX_BAR.equals(wayCode)) {
            WxBarOrderExtRQ bizRQ = JSONObject.parseObject(StringUtils.defaultIfEmpty(this.channelExtra, "{}"), WxBarOrderExtRQ.class);
            BeanUtils.copyProperties(this, bizRQ);
            return bizRQ;
        } else if (Cs.PAY_WAY_CODE.WX_NATIVE.equals(wayCode)) {
            WxNativeOrderRQ bizRQ = JSONObject.parseObject(StringUtils.defaultIfEmpty(this.channelExtra, "{}"), WxNativeOrderRQ.class);
            BeanUtils.copyProperties(this, bizRQ);
            return bizRQ;
        } else if (Cs.PAY_WAY_CODE.WX_H5.equals(wayCode)) {
            WxH5OrderRQ bizRQ = JSONObject.parseObject(StringUtils.defaultIfEmpty(this.channelExtra, "{}"), WxH5OrderRQ.class);
            BeanUtils.copyProperties(this, bizRQ);
            return bizRQ;
        } else if (Cs.PAY_WAY_CODE.YSF_BAR.equals(wayCode)) {
            YsfBarOrderExtRQ bizRQ = JSONObject.parseObject(StringUtils.defaultIfEmpty(this.channelExtra, "{}"), YsfBarOrderExtRQ.class);
            BeanUtils.copyProperties(this, bizRQ);
            return bizRQ;
        } else if (Cs.PAY_WAY_CODE.YSF_JSAPI.equals(wayCode)) {
            YsfJsapiOrderExtRQ bizRQ = JSONObject.parseObject(StringUtils.defaultIfEmpty(this.channelExtra, "{}"), YsfJsapiOrderExtRQ.class);
            BeanUtils.copyProperties(this, bizRQ);
            return bizRQ;
        } else if (Cs.PAY_WAY_CODE.AUTO_BAR.equals(wayCode)) {
            AutoBarOrderExtRQ bizRQ = JSONObject.parseObject(StringUtils.defaultIfEmpty(this.channelExtra, "{}"), AutoBarOrderExtRQ.class);
            BeanUtils.copyProperties(this, bizRQ);
            return bizRQ;
        } else if (Cs.PAY_WAY_CODE.ALI_APP.equals(wayCode)) {
            AliAppOrderExtRQ bizRQ = JSONObject.parseObject(StringUtils.defaultIfEmpty(this.channelExtra, "{}"), AliAppOrderExtRQ.class);
            BeanUtils.copyProperties(this, bizRQ);
            return bizRQ;
        } else if (Cs.PAY_WAY_CODE.ALI_WAP.equals(wayCode)) {
            AliWapOrderRQ bizRQ = JSONObject.parseObject(StringUtils.defaultIfEmpty(this.channelExtra, "{}"), AliWapOrderRQ.class);
            BeanUtils.copyProperties(this, bizRQ);
            return bizRQ;
        } else if (Cs.PAY_WAY_CODE.ALI_PC.equals(wayCode)) {
            AliPcOrderRQ bizRQ = JSONObject.parseObject(StringUtils.defaultIfEmpty(this.channelExtra, "{}"), AliPcOrderRQ.class);
            BeanUtils.copyProperties(this, bizRQ);
            return bizRQ;
        } else if (Cs.PAY_WAY_CODE.ALI_QR.equals(wayCode)) {
            AliQrOrderRQ bizRQ = JSONObject.parseObject(StringUtils.defaultIfEmpty(this.channelExtra, "{}"), AliQrOrderRQ.class);
            BeanUtils.copyProperties(this, bizRQ);
            return bizRQ;
        } else if (Cs.PAY_WAY_CODE.PP_PC.equals(wayCode)) {
            PPPcOrderRQ bizRQ = JSONObject.parseObject(StringUtils.defaultIfEmpty(this.channelExtra, "{}"), PPPcOrderRQ.class);
            BeanUtils.copyProperties(this, bizRQ);
            return bizRQ;
        }
        return this;
    }

    /**
     * 获取渠道用户ID
     */
    @JSONField(serialize = false)
    public String getChannelUserId() {
        return null;
    }

}
